home *** CD-ROM | disk | FTP | other *** search
- /*+
- * File: crc16.c
- * Description:
- * Computes crc for the named filenames.
- * Output has this formatt.
- * file=[i_file], size=[fsize], crc=[decval](dec)=[hexval](hex)
- *
- * Usages:
- * crc16 <i_files>
- *
- * Author: Mohsen Banan.
- *
- * This program is public domain software, no warranty intended or
- * implied.
- * General permission to copy or modify, but not for profit, is
- * hereby granted.
- *
- * Functions:
- *
- *
- * Audit Trail: $Log: crc16.c,v $
- * Revision 1.1 85/08/28 08:38:12 mohsen
- * original posting to the net
- *
- *
- *
- -*/
-
- #ifdef RCS_VER
- static char *rcs = "$Header: crc16.c,v 1.1 85/08/28 08:38:12 mohsen Exp $";
- #endif
-
- /* #includes */
- #include "mbstd.h"
- #include <stdio.h>
- #include <ctype.h>
- #include <fcntl.h>
- #ifdef unix
- #include "msc3.h"
- #endif
-
- /* #defines */
-
- /* external variables */
-
- /* referenced external function declarations */
- EXTERN USHORT fcrc16();
- /* internal function declarations */
- PUBLIC VOID crc16();
- PUBLIC VOID cant_open();
- STATIC VOID usage();
-
- /* global variables */
-
- /* static variables */
- STATIC CHAR * prog_name;
-
-
- INT
- main (argc, argv)
- INT argc;
- CHAR * argv[];
- {
- crc16(argc, argv);
- }
-
-
- /*<
- * Function:crc16
- * Description:
- *
- * Returns:
- * VOID
- *
- >*/
- PUBLIC VOID
- crc16 (argc,argv)
- INT argc;
- CHAR * argv[];
- {
- FILE * i_fp;
- FILE * o_fp;
-
- INT i;
- USHORT crc;
- LONG fsize ;
-
- i_fp = stdin;
- o_fp = stdout;
- prog_name = argv[0];
- for (i=1; i<argc; ++i) {
- if (*argv[i] == '-') {
- /* To handle concatenated switches */
- INT j;
- j=i;
- while (*(++argv[j])) {
- switch (*argv[j]) {
- case 'o':
- case 'O':
- if ( !(o_fp = fopen(argv[++i], "w")) ) {
- cant_open (prog_name, argv[i]);
- exit (1);
- }
- break;
- default:
- usage();
- exit(1);
- } /* switch (*argv[j]) */
- } /* while (*(++argv[j])) */
- } /* if '-' */
- else {
- if (!(i_fp = fopen (argv[i], "r"))) {
- cant_open (prog_name, argv[i]);
- exit (1);
- }
- setmode (fileno(i_fp), O_BINARY);
- setmode (fileno(o_fp), O_TEXT);
- crc = fcrc16 (i_fp, 0, &fsize);
- fprintf (o_fp, "file=%s, size=%ld, crc=%u(dec)=%x(hex)\n",
- argv[i], fsize, crc, crc);
- fclose (i_fp);
- }
- } /* for i<argc */
- fclose (o_fp);
- exit (0);
- }
-
- PUBLIC VOID
- cant_open (prog_name,filename)
- CHAR * prog_name;
- CHAR * filename;
- {
- fprintf (stderr, "%s :can not open %s \n", prog_name, filename);
- }
-
- STATIC VOID
- usage ()
- {
- fprintf (stderr, "Usage: %s <i_files> \n", prog_name);
- }
-
-
-
-